package suo;


import org.dom4j.DocumentException;


import java.beans.IntrospectionException;
import java.beans.PropertyVetoException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;

public class MyPer {
    public static void main(String[] args) throws IllegalAccessException, IntrospectionException, InstantiationException, SQLException, InvocationTargetException, NoSuchFieldException, DocumentException, PropertyVetoException, ClassNotFoundException {
        //读取配置文件，先将配置文件以流的形式读取到内存中，然后再解析封装成javaBean。
        /*ClassLoader classLoader = Resource.class.getClassLoader();
        InputStream resourceAsStream1 = classLoader.getResourceAsStream("sqlMapConfig.xml");*/
        InputStream resourceAsStream = Resources.class.getClassLoader().getResourceAsStream("sqlMapConfig.xml");
        //有了数据库连接信息和SQL信息，剩下的事交给框架去做即可。我们是需要再做一件事，指定使用那一条SQL语句和接收返回值
        SqlSessionFactory sqlSessionFactory = new SqlSessFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSqlSession();
        User user = new User();
        user.setName("tom");

        //statementID存在硬编码问题，需要改进，User.selectOne中,User是由namespace来的，selectOne是由id来的，考虑通过某种方式，将这两个值进行关联
        //List<User> objects = sqlSession.selectList("User.selectOne", user);
        UserMapper mappper = sqlSession.getMappper(UserMapper.class);
        User user1 = mappper.selectOne(user);
        Integer i=1;

        //更新
        user1.setAge(100);
        mappper.update(13,"tom");
        /*for (User object : objects) {
            System.out.println(object);
        }*/
    }
}
